/*
 * ByteStream.h
 *
 *  Created on: Jun 25, 2012
 *      Author: burek
 */

#ifndef BYTESTREAM_H_
#define BYTESTREAM_H_

#include "integers.h"

struct ByteStream
{
	byte * data;
	uint32_t length;
	uint32_t bufferSize;
	uint32_t pos;

	ByteStream(uint32_t bSize);
	ByteStream(const char * fileName);
	ByteStream(void * buffer, int32_t size);
	~ByteStream();
	void zeroMem();
	int32_t seekStreamTo(uint32_t pos);
	int32_t seekToStart();
	int32_t seekToEnd();
	bool writeSHORT(int16_t x);
	bool writeUSHORT(uint16_t x);
	bool writeINT(int32_t x);
	bool writeUINT(uint32_t x);
	bool writeLONG(int64_t x);
	bool writeULONG(uint64_t x);
	bool writeBOOL(bool b);
	bool writeFLOAT(float f);
	bool writeCHAR(char c);
	bool writeUCHAR(unsigned char c);
	bool writeSTRING(const char * s, uint32_t maxLen);
	bool writeSTRINGn(const char * s, uint32_t maxLen);
	bool writeBUFFER(ByteStream * bs);
	bool writeBYTES(byte * b, uint32_t len);
	bool readSHORT(int16_t & x);
	bool readUSHORT(uint16_t & x);
	bool readINT(int32_t & x);
	bool readUINT(uint32_t & x);
	bool readLONG(int64_t & x);
	bool readULONG(uint64_t & x);
	bool readBOOL(bool & b);
	bool readFLOAT(float & f);
	bool readCHAR(char & c);
	bool readUCHAR(unsigned char & c);
	bool readSTRING(char * s, uint32_t maxLen);
	bool readLINE(char * s, uint32_t maxLen);
	bool readBUFFER(ByteStream * bs, uint32_t len);
	bool readBYTES(byte * b, uint32_t len);

	bool writePlain(const char * name);
	bool readPlain(const char * name);
};


#endif /* BYTESTREAM_H_ */
